<!-- <template>
  <transition name="fade">
    <sub-com v-if="show">
      {{ content }}
    </sub-com>
    <div v-else>组件已销毁</div>
  </transition>
  <button @click="changeShow">测试</button>
</template> -->

<!-- CSS 的 transition -->
<!-- <template>
  <transition name="slide-fade">
      <div v-if="show">Hello World! {{ content }}</div>
  </transition>
  <button @click="changeShow">测试</button>
</template> -->

<!-- CSS 的 animation -->
<!-- <template>
  <Transition name="bounce">
    <p v-if="show" style="text-align: center;">
      Hello here is some bouncy text!
    </p>
  </Transition>
  <button @click="changeShow">测试</button>
</template> -->

<!-- 自定义过渡 class -->
<!-- <template>
  <Transition name="custom-classes" enter-active-class="animate__animated animate__tada"
    leave-active-class="animate__animated animate__bounceOutRight">
    <p v-if="show">Hello World</p>
  </Transition>
  <button @click="changeShow">测试</button>
</template> -->

<!-- 过渡模式 -->
<template>
  <span style="margin-right: 20px">Click to cycle through states:</span>
  <div class="btn-container">
    <Transition name="slide-up">
        <button v-if="docState === 'saved'" @click="docState = 'edited'">Edit</button>
        <button v-else-if="docState === 'edited'" @click="docState = 'editing'">Save</button>
        <button v-else-if="docState === 'editing'" @click="docState = 'saved'">Cancel</button>
      </Transition>
    <!-- <Transition mode="out-in">
      <button v-if="docState === 'saved'" @click="docState = 'edited'">
        Edit
      </button>
      <button v-else-if="docState === 'edited'" @click="docState = 'editing'">
        Save
      </button>
      <button v-else-if="docState === 'editing'" @click="docState = 'saved'">
        Cancel
      </button>
    </Transition> -->
  </div>
</template>

<!--
1、基本使用
2、命名使用
3、
-->
<script setup>
import { ref } from 'vue'
import SubCom from '@/components/chapter08/base/7.6.2SubCom.vue'

const docState = ref('saved')
const show = ref(true)
const content = ref(0)

const changeShow = () => {
  show.value = !show.value
  content.value += 1
}
</script>

<style scoped>
@import 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css';

.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/*
  进入和离开动画可以使用不同
  持续时间和速度曲线。
*/
.slide-fade-enter-active {
  transition: all 0.3s ease-out;
}

.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateX(20px);
  opacity: 0;
}

.bounce-enter-active {
  animation: bounce-in 0.5s;
}

.bounce-leave-active {
  animation: bounce-in 0.5s reverse;
}

@keyframes bounce-in {
  0% {
    transform: scale(0);
  }

  50% {
    transform: scale(1.25);
  }

  100% {
    transform: scale(1);
  }
}

.btn-container {
  display: inline-block;
  position: relative;
  height: 2em;
}

button {
  position: absolute;
}

.slide-up-enter-active,
.slide-up-leave-active {
  transition: all 0.25s ease-out;
}

.slide-up-enter-from {
  opacity: 0;
  transform: translateY(30px);
}

.slide-up-leave-to {
  opacity: 0;
  transform: translateY(-30px);
}
</style>
